/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package turnibook.view;

import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JToolBar;
import javax.swing.table.DefaultTableModel;
import turnibook.model.Operaciones;


/**
 *
 * @author wrtfix
 */
public class Usuarios extends javax.swing.JFrame {
  
    /**
     * Creates new form Usuarios
     */
    public Usuarios() {
        initComponents();
        tablaProfesional.addMouseListener(new MouseAdapter() {
            @Override
              public void mouseClicked(MouseEvent e) 
              {
                 int fila = tablaProfesional.rowAtPoint(e.getPoint());
                 int columna = tablaProfesional.columnAtPoint(e.getPoint());
                    
              }
        });
        agregarProfesionales();
     
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jMenuItem1 = new javax.swing.JMenuItem();
        jLabel2 = new javax.swing.JLabel();
        nombreProfesional = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        contraProfesional = new javax.swing.JPasswordField();
        jScrollPane1 = new javax.swing.JScrollPane();
        tablaProfesional = new javax.swing.JTable();
        botonAgregar = new javax.swing.JToggleButton();
        botonGenerar = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        intervalo = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        checkLunes = new javax.swing.JCheckBox();
        checkMartes = new javax.swing.JCheckBox();
        checkMiercoles = new javax.swing.JCheckBox();
        checkJueves = new javax.swing.JCheckBox();
        lunesDesde = new javax.swing.JTextField();
        lunesHasta = new javax.swing.JTextField();
        martesHasta = new javax.swing.JTextField();
        martesDesde = new javax.swing.JTextField();
        miercolesHasta = new javax.swing.JTextField();
        miercolesDesde = new javax.swing.JTextField();
        juevesHasta = new javax.swing.JTextField();
        juevesDesde = new javax.swing.JTextField();
        checkViernes = new javax.swing.JCheckBox();
        viernesDesde = new javax.swing.JTextField();
        viernesHasta = new javax.swing.JTextField();
        checkSabado = new javax.swing.JCheckBox();
        sabadoDesde = new javax.swing.JTextField();
        sabadoHasta = new javax.swing.JTextField();
        checkDomingo = new javax.swing.JCheckBox();
        domingoDesde = new javax.swing.JTextField();
        domingoHasta = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        botonAgenda = new javax.swing.JButton();
        jLabel6 = new javax.swing.JLabel();
        mail = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        aviso1 = new javax.swing.JTextField();

        jMenuItem1.setText("jMenuItem1");

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Configuracion de Usuario");
        setResizable(false);

        jLabel2.setText("Nombre");

        jLabel3.setText("Contraseña");

        tablaProfesional.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Numero de Profesional", "Nombre", "Password", "Mail"
            }
        ));
        tablaProfesional.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tablaProfesionalMouseClicked(evt);
            }
        });
        tablaProfesional.addInputMethodListener(new java.awt.event.InputMethodListener() {
            public void caretPositionChanged(java.awt.event.InputMethodEvent evt) {
            }
            public void inputMethodTextChanged(java.awt.event.InputMethodEvent evt) {
                tablaProfesionalInputMethodTextChanged(evt);
            }
        });
        tablaProfesional.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                tablaProfesionalKeyPressed(evt);
            }
            public void keyTyped(java.awt.event.KeyEvent evt) {
                tablaProfesionalKeyTyped(evt);
            }
        });
        jScrollPane1.setViewportView(tablaProfesional);

        botonAgregar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/turnibook/images/ico_agregar.gif"))); // NOI18N
        botonAgregar.setText("Agregar");
        botonAgregar.setMaximumSize(new java.awt.Dimension(93, 29));
        botonAgregar.setMinimumSize(new java.awt.Dimension(93, 29));
        botonAgregar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                botonAgregarMouseClicked(evt);
            }
        });
        botonAgregar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonAgregarActionPerformed(evt);
            }
        });

        botonGenerar.setText("Generar");
        botonGenerar.setEnabled(false);
        botonGenerar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                botonGenerarMouseClicked(evt);
            }
        });
        botonGenerar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonGenerarActionPerformed(evt);
            }
        });

        jLabel1.setText("Intervalors de turno");

        intervalo.setText("15");

        jLabel4.setText("Dias Laborales");

        checkLunes.setText("Lunes");
        checkLunes.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                checkLunesActionPerformed(evt);
            }
        });

        checkMartes.setText("Martes");
        checkMartes.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                checkMartesActionPerformed(evt);
            }
        });

        checkMiercoles.setText("Miercoles");
        checkMiercoles.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                checkMiercolesActionPerformed(evt);
            }
        });

        checkJueves.setText("Jueves");
        checkJueves.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                checkJuevesActionPerformed(evt);
            }
        });

        lunesDesde.setEditable(false);
        lunesDesde.setText("0");

        lunesHasta.setEditable(false);
        lunesHasta.setText("0");
        lunesHasta.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                lunesHastaActionPerformed(evt);
            }
        });

        martesHasta.setEditable(false);
        martesHasta.setText("0");

        martesDesde.setEditable(false);
        martesDesde.setText("0");
        martesDesde.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                martesDesdeActionPerformed(evt);
            }
        });

        miercolesHasta.setEditable(false);
        miercolesHasta.setText("0");

        miercolesDesde.setEditable(false);
        miercolesDesde.setText("0");

        juevesHasta.setEditable(false);
        juevesHasta.setText("0");

        juevesDesde.setEditable(false);
        juevesDesde.setText("0");

        checkViernes.setText("Viernes");
        checkViernes.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                checkViernesActionPerformed(evt);
            }
        });

        viernesDesde.setEditable(false);
        viernesDesde.setText("0");

        viernesHasta.setEditable(false);
        viernesHasta.setText("0");

        checkSabado.setText("Sabado");
        checkSabado.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                checkSabadoActionPerformed(evt);
            }
        });

        sabadoDesde.setEditable(false);
        sabadoDesde.setText("0");

        sabadoHasta.setEditable(false);
        sabadoHasta.setText("0");

        checkDomingo.setText("Domingo");
        checkDomingo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                checkDomingoActionPerformed(evt);
            }
        });

        domingoDesde.setEditable(false);
        domingoDesde.setText("0");

        domingoHasta.setEditable(false);
        domingoHasta.setText("0");

        jLabel5.setText("Hasta");

        botonAgenda.setText("Agenda");
        botonAgenda.setEnabled(false);
        botonAgenda.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonAgendaActionPerformed(evt);
            }
        });

        jLabel6.setText("Mail");

        jLabel8.setText("Desde");

        aviso1.setEditable(false);
        aviso1.setBorder(null);
        aviso1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                aviso1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(botonAgenda, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addGroup(layout.createSequentialGroup()
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                            .addComponent(checkDomingo, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                            .addComponent(jLabel4, javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(checkLunes, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                            .addComponent(checkSabado, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                            .addComponent(checkViernes, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                            .addComponent(checkJueves, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                            .addComponent(checkMiercoles, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                            .addComponent(checkMartes, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                        .addGap(0, 0, Short.MAX_VALUE)))
                                .addGap(6, 6, 6)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(sabadoDesde)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(sabadoHasta, javax.swing.GroupLayout.PREFERRED_SIZE, 172, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                        .addComponent(domingoDesde)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                            .addComponent(domingoHasta)
                                            .addComponent(botonGenerar, javax.swing.GroupLayout.PREFERRED_SIZE, 172, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                            .addComponent(juevesDesde, javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(viernesDesde))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                            .addComponent(viernesHasta)
                                            .addComponent(juevesHasta, javax.swing.GroupLayout.PREFERRED_SIZE, 172, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(martesDesde)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(martesHasta, javax.swing.GroupLayout.PREFERRED_SIZE, 172, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(miercolesDesde)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(miercolesHasta, javax.swing.GroupLayout.PREFERRED_SIZE, 172, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(lunesDesde)
                                            .addGroup(layout.createSequentialGroup()
                                                .addComponent(jLabel8)
                                                .addGap(0, 0, Short.MAX_VALUE)))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jLabel5)
                                            .addComponent(lunesHasta, javax.swing.GroupLayout.PREFERRED_SIZE, 172, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 1, Short.MAX_VALUE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(intervalo, javax.swing.GroupLayout.PREFERRED_SIZE, 431, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jScrollPane1))
                        .addContainerGap())
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel3)
                            .addComponent(jLabel2)
                            .addComponent(jLabel6))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(contraProfesional)
                            .addComponent(nombreProfesional)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addGap(0, 0, Short.MAX_VALUE)
                                .addComponent(mail, javax.swing.GroupLayout.PREFERRED_SIZE, 449, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(4, 4, 4))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(botonAgregar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(aviso1, javax.swing.GroupLayout.PREFERRED_SIZE, 286, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(0, 0, Short.MAX_VALUE))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(nombreProfesional, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel2))
                        .addGap(24, 24, 24))
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel3)
                        .addComponent(contraProfesional, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(mail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(botonAgregar, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 117, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(intervalo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel5, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel4)
                        .addComponent(jLabel8)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(checkLunes)
                    .addComponent(lunesDesde, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lunesHasta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(checkMartes)
                    .addComponent(martesDesde, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(martesHasta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(checkMiercoles)
                    .addComponent(miercolesDesde, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(miercolesHasta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(checkJueves)
                    .addComponent(juevesDesde, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(juevesHasta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(checkViernes)
                    .addComponent(viernesDesde, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(viernesHasta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(checkSabado)
                    .addComponent(sabadoDesde, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(sabadoHasta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(checkDomingo)
                    .addComponent(domingoDesde, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(domingoHasta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(botonGenerar)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(2, 2, 2)
                        .addComponent(botonAgenda, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(aviso1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
    // Este metodo consulta una tabla
    public void agregarProfesionales(){
        // Creo una instacia de operaciones
        Operaciones o = new Operaciones();
        // Guardo en un clase del tipo resultado de consulta la consulta que hice sobre operaciones
        ResultSet resultado = o.consultar("select * from profesional");
        try {
            DefaultTableModel model = (DefaultTableModel) tablaProfesional.getModel();
            while(resultado.next()){
                //Obtengo los elementos de resultado.getString(numero de columna)
                model.addRow(new Object[]{resultado.getString(1),resultado.getString(3), resultado.getString(4),resultado.getString(5)});
            }
        } catch (SQLException ex) {
            Logger.getLogger(Usuarios.class.getName()).log(Level.SEVERE, null, ex);
        }
        
    }
    private void botonAgregarMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_botonAgregarMouseClicked
    }//GEN-LAST:event_botonAgregarMouseClicked

    private void removerTabla(){
        int row = tablaProfesional.getSelectedRow();
        if (row>=0){
             DefaultTableModel model = (DefaultTableModel) tablaProfesional.getModel();
             model.removeRow(row);
        }else{
            JOptionPane.showMessageDialog(null, "Debe seleccionar algun profesional");
        }
    }
    private void tablaProfesionalInputMethodTextChanged(java.awt.event.InputMethodEvent evt) {//GEN-FIRST:event_tablaProfesionalInputMethodTextChanged
        // TODO add your handling code here:
    }//GEN-LAST:event_tablaProfesionalInputMethodTextChanged

    private void botonAgregarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonAgregarActionPerformed
        if(!nombreProfesional.getText().isEmpty() && !contraProfesional.getText().isEmpty()){
            DefaultTableModel model = (DefaultTableModel) tablaProfesional.getModel();
            //Cargar los profesionales existentes
            model.addRow(new Object[]{model.getRowCount()+1,nombreProfesional.getText(), contraProfesional.getText(),mail.getText()});
            
            
        }else
        {
            JOptionPane.showMessageDialog(null, "Debe ingresar nombre de profesional y password");
        }
    }//GEN-LAST:event_botonAgregarActionPerformed

    private void tablaProfesionalKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tablaProfesionalKeyPressed

    }//GEN-LAST:event_tablaProfesionalKeyPressed
    
    private void botonGenerarMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_botonGenerarMouseClicked
            
    }//GEN-LAST:event_botonGenerarMouseClicked

    private void lunesHastaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_lunesHastaActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_lunesHastaActionPerformed

    private void checkLunesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkLunesActionPerformed
       if(checkLunes.isSelected()){
            lunesDesde.setEditable(true);
            lunesHasta.setEditable(true);
            lunesDesde.grabFocus();
                   
        }
        else{
            lunesDesde.setEditable(false);
            lunesHasta.setEditable(false);
        }
    }//GEN-LAST:event_checkLunesActionPerformed

    private void checkMartesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkMartesActionPerformed
         if(checkMartes.isSelected()){
            martesDesde.setEditable(true);
            martesHasta.setEditable(true);
            miercolesDesde.grabFocus();
        }
        else{
            martesDesde.setEditable(false);
            martesHasta.setEditable(false);
        }
    }//GEN-LAST:event_checkMartesActionPerformed

    private void botonGenerarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonGenerarActionPerformed
        Operaciones o = new Operaciones();
                        
            String nombre = tablaProfesional.getValueAt(tablaProfesional.getSelectedRow(),1).toString();
            String id_profesional = tablaProfesional.getValueAt(tablaProfesional.getSelectedRow(),0).toString();
            String clave = tablaProfesional.getValueAt(tablaProfesional.getSelectedRow(),2).toString();
            String mail = tablaProfesional.getValueAt(tablaProfesional.getSelectedRow(),3).toString();
            String sql = null;
            String sql2 = null;
            
            if (!o.existeProfesional(id_profesional)){
                
                sql = "insert into horario(lunes_desde, lunes_hasta,martes_desde,martes_hasta,miercoles_desde,miercoles_hasta,jueves_desde, jueves_hasta, viernes_desde, viernes_hasta, sabado_desde, sabado_hasta, domingo_desde, domingo_hasta, intervalo ) values('" ;
                sql = sql + lunesDesde.getText() + "','" + lunesHasta.getText() + "','" + martesDesde.getText() + "','" + martesHasta.getText() + "','" + miercolesDesde.getText() + "','" + miercolesHasta.getText() + "','" + juevesDesde.getText() + "','" + juevesHasta.getText() + "','" + viernesDesde.getText() + "','" + viernesHasta.getText() + "','" + sabadoDesde.getText() + "','" + sabadoHasta.getText() + "','" + domingoDesde.getText() + "','" + domingoHasta.getText() + "'," + intervalo.getText() +")";
            
            
                o.insertar(sql,aviso1);
                String id_horario = o.ultimoIdHorario();
                sql2 = "insert into profesional(id_horario,nombre,clave,email) values ("+id_horario +",'"+nombre+"','"+clave+"','"+mail+"')";
                o.insertar(sql2,aviso1);
            }else{
                String id_horario = o.IdHorario(id_profesional);
                sql = "update horario set lunes_desde='"+lunesDesde.getText()+"' , lunes_hasta='"+lunesHasta.getText()+"' , martes_desde='"+martesDesde.getText()+"' , martes_hasta='"+ martesHasta.getText() +"' , miercoles_desde='"+miercolesDesde.getText()+"' , miercoles_hasta='"+miercolesHasta.getText()+"' , jueves_desde='"+juevesDesde.getText()+"' , jueves_hasta='"+juevesHasta.getText()+"' , viernes_desde='"+viernesDesde.getText()+"' , viernes_hasta='"+viernesHasta.getText()+"' , sabado_desde='"+sabadoDesde.getText()+"' , sabado_hasta='"+sabadoHasta.getText()+"' , domingo_desde='"+domingoDesde.getText()+"' , domingo_hasta='"+domingoHasta.getText()+"' , intervalo='"+intervalo.getText()+"' where id_horario='"+id_horario+"'";
            
                o.insertar(sql,aviso1); 
                sql2 = "update profesional set nombre='"+nombre+"' , clave='"+clave+"' , email='"+mail+"' where id_profesional='"+id_profesional+"'";
                o.insertar(sql2,aviso1);
            }
            
    }//GEN-LAST:event_botonGenerarActionPerformed

    private void checkMiercolesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkMiercolesActionPerformed
         if(checkMiercoles.isSelected()){
            miercolesDesde.setEditable(true);
            miercolesHasta.setEditable(true);
            miercolesDesde.grabFocus();
        }
        else{
            miercolesDesde.setEditable(false);
            miercolesHasta.setEditable(false);
        }
    }//GEN-LAST:event_checkMiercolesActionPerformed

    private void checkJuevesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkJuevesActionPerformed
        if(checkJueves.isSelected()){
            juevesDesde.setEditable(true);
            juevesHasta.setEditable(true);
            juevesDesde.grabFocus();
        }
        else{
            juevesDesde.setEditable(false);
            juevesHasta.setEditable(false);
        }
    }//GEN-LAST:event_checkJuevesActionPerformed

    private void checkViernesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkViernesActionPerformed
        if(checkViernes.isSelected()){
            viernesDesde.setEditable(true);
            viernesHasta.setEditable(true);
            viernesDesde.grabFocus();
        }
        else{
            viernesDesde.setEditable(false);
            viernesHasta.setEditable(false);
        }
    }//GEN-LAST:event_checkViernesActionPerformed

    private void checkSabadoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkSabadoActionPerformed
                if(checkSabado.isSelected()){
            sabadoDesde.setEditable(true);
            sabadoHasta.setEditable(true);
            sabadoDesde.grabFocus();
            
        }
        else{
            sabadoDesde.setEditable(false);
            sabadoHasta.setEditable(false);
        }
    }//GEN-LAST:event_checkSabadoActionPerformed

    private void checkDomingoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkDomingoActionPerformed
            if(checkDomingo.isSelected()){
            domingoDesde.grabFocus();
            domingoDesde.setEditable(true);
            domingoHasta.setEditable(true);
        }
        else{
            domingoDesde.setEditable(false);
            domingoHasta.setEditable(false);
        }
    }//GEN-LAST:event_checkDomingoActionPerformed

    private void botonAgendaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonAgendaActionPerformed
            Agenda ct = new Agenda();
            
            Operaciones o = new Operaciones();
            String id_profesional = tablaProfesional.getValueAt(tablaProfesional.getSelectedRow(),0).toString();
            ct.setId_horario(o.IdHorario(id_profesional));
            ct.setId_profesional(id_profesional);
            ct.setEmail(tablaProfesional.getValueAt(tablaProfesional.getSelectedRow(),3).toString());
            ct.setLocationRelativeTo(null);
            ct.setVisible(true);
            ct.pack();
            this.setVisible(false);
    }//GEN-LAST:event_botonAgendaActionPerformed

    private void martesDesdeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_martesDesdeActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_martesDesdeActionPerformed

    private void tablaProfesionalMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tablaProfesionalMouseClicked
        try {
            botonGenerar.setEnabled(true);
            botonAgenda.setEnabled(true);
            String id_profesional = tablaProfesional.getValueAt(tablaProfesional.getSelectedRow(),0).toString();
            Operaciones o = new Operaciones();
            String id = o.IdHorario(id_profesional);
            ResultSet res = o.getHorarios(id);
            
            if (res.next()){
            lunesDesde.setText(res.getString("lunes_desde"));
            lunesHasta.setText(res.getString("lunes_hasta"));
            martesDesde.setText(res.getString("martes_desde"));
            martesHasta.setText(res.getString("martes_hasta"));
            miercolesDesde.setText(res.getString("miercoles_desde"));
            miercolesHasta.setText(res.getString("miercoles_hasta"));
            juevesDesde.setText(res.getString("jueves_desde"));
            juevesHasta.setText(res.getString("jueves_hasta"));
            viernesDesde.setText(res.getString("viernes_desde"));
            viernesHasta.setText(res.getString("viernes_hasta"));
            sabadoDesde.setText(res.getString("sabado_desde"));
            sabadoHasta.setText(res.getString("sabado_hasta"));
            domingoDesde.setText(res.getString("domingo_desde"));
            domingoHasta.setText(res.getString("domingo_hasta"));
            intervalo.setText(res.getString("intervalo"));
            }
            o.closeDB();
        } catch (SQLException ex) {
            Logger.getLogger(Usuarios.class.getName()).log(Level.SEVERE, null, ex);
        }
        
    }//GEN-LAST:event_tablaProfesionalMouseClicked

    private void tablaProfesionalKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tablaProfesionalKeyTyped
    }//GEN-LAST:event_tablaProfesionalKeyTyped

    private void aviso1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_aviso1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_aviso1ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Usuarios.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Usuarios.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Usuarios.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Usuarios.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Usuarios().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField aviso1;
    private javax.swing.JButton botonAgenda;
    private javax.swing.JToggleButton botonAgregar;
    private javax.swing.JButton botonGenerar;
    private javax.swing.JCheckBox checkDomingo;
    private javax.swing.JCheckBox checkJueves;
    private javax.swing.JCheckBox checkLunes;
    private javax.swing.JCheckBox checkMartes;
    private javax.swing.JCheckBox checkMiercoles;
    private javax.swing.JCheckBox checkSabado;
    private javax.swing.JCheckBox checkViernes;
    private javax.swing.JPasswordField contraProfesional;
    private javax.swing.JTextField domingoDesde;
    private javax.swing.JTextField domingoHasta;
    private javax.swing.JTextField intervalo;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextField juevesDesde;
    private javax.swing.JTextField juevesHasta;
    private javax.swing.JTextField lunesDesde;
    private javax.swing.JTextField lunesHasta;
    private javax.swing.JTextField mail;
    private javax.swing.JTextField martesDesde;
    private javax.swing.JTextField martesHasta;
    private javax.swing.JTextField miercolesDesde;
    private javax.swing.JTextField miercolesHasta;
    private javax.swing.JTextField nombreProfesional;
    private javax.swing.JTextField sabadoDesde;
    private javax.swing.JTextField sabadoHasta;
    private javax.swing.JTable tablaProfesional;
    private javax.swing.JTextField viernesDesde;
    private javax.swing.JTextField viernesHasta;
    // End of variables declaration//GEN-END:variables
}
